package com.hoow.shakoow.ai.home

import android.graphics.Bitmap
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import com.hoow.shakoow.ai.data.*
import com.hoow.shakoow.base.BaseViewModel
import com.hoow.shakoow.ai.network.ApiAiReposity
import com.hoow.shakoow.shake.adapter.UserFeedbackImage


class NetworkViewModel : BaseViewModel() {

    /** 图片本地路径 */
    var mImagePath = ""

    /** 图片oss路径 */
    var mImageUrl = ""

    /** 图片oss路径 */
    var mImageBitmap: Bitmap? = null

    /** 当前图片选择类型 */
    var mImageAction: Int = 0

    /**
     * app-获取APP更新版本
     */
    private val mGetAppVersionLiveData = MutableLiveData<ReqAiBase>()

    /**
     * app-获取APP更新版本-回调
     */
    val onGetAppVersionLiveData =
        Transformations.switchMap(mGetAppVersionLiveData) { query ->
            ApiAiReposity.getAppVersion(this, query)
        }

    /**
     * app-获取APP更新版本
     */
    fun getAppVersion(reqAiBase: ReqAiBase) {
        mGetAppVersionLiveData.value = reqAiBase
    }
    ///////////////////////////////////////

    /**
     * app-获取APP配置
     */
    private val mGetAppConfigLiveData = MutableLiveData<ReqAiBase>()

    /**
     * app-获取APP配置-回调
     */
    val onGetAppConfigLiveData =
        Transformations.switchMap(mGetAppConfigLiveData) { query ->
            ApiAiReposity.getAppConfig(this, query)
        }

    /**
     * app-获取APP配置
     */
    fun getAppConfig(reqAiBase: ReqAiBase) {
        mGetAppConfigLiveData.value = reqAiBase
    }
    ///////////////////////////////////////



    /**
     * 登录-广告id登录
     */
    private val mLoginByAdvertIdLiveData = MutableLiveData<ReqAiBase>()

    /**
     * 登录-广告id登录-回调
     */
    val onLoginByAdvertIdLiveData =
        Transformations.switchMap(mLoginByAdvertIdLiveData) { query ->
            ApiAiReposity.loginByAdvertId(this, query)
        }

    /**
     * 登录-广告id登录
     */
    fun loginByAdvertId(reqAiBase: ReqAiBase) {
        mLoginByAdvertIdLiveData.value = reqAiBase
    }
    ///////////////////////////////////////


    /**
     * 用户-获取用户详情
     */
    private val mGetUserInfoLiveData = MutableLiveData<ReqAiBase>()

    /**
     * 用户-获取用户详情-回调
     */
    val onGetUserInfoLiveData =
        Transformations.switchMap(mGetUserInfoLiveData) { query ->
            ApiAiReposity.getUserInfo(this, query)
        }

    /**
     * 用户-获取用户详情
     */
    fun getUserInfo(reqAiBase: ReqAiBase) {
        reqAiBase.showLoading = false
        mGetUserInfoLiveData.value = reqAiBase
    }
    ///////////////////////////////////////

    /**
     * 用户-获取用户详情 根据id
     */
    private val mGetUserInfoByUserIdLiveData = MutableLiveData<ReqAiBase>()

    /**
     * 用户-获取用户详情 根据id-回调
     */
    val onGetUserInfoByUserIdLiveData =
        Transformations.switchMap(mGetUserInfoByUserIdLiveData) { query ->
            ApiAiReposity.getUserInfoByUserId(this, query)
        }

    /**
     * 用户-获取用户详情 根据id
     */
    fun getUserInfoByUserId(reqAiBase: ReqAiBase) {
        reqAiBase.showLoading = false
        mGetUserInfoByUserIdLiveData.value = reqAiBase
    }
    ///////////////////////////////////////

    /**
     * 工具-上传文件
     */
    private val mUploadFileLiveData = MutableLiveData<ReqImageUpload>()

    /**
     * 工具-上传文件-回调
     */
    val onUploadFileLiveData =
        Transformations.switchMap(mUploadFileLiveData) { query ->
            ApiAiReposity.uploadFile(this, query)
        }

    /**
     * 工具-上传文件
     */
    fun uploadFile(reqImageUpload: ReqImageUpload) {
        mUploadFileLiveData.value = reqImageUpload
    }
    ///////////////////////////////////////

    /**
     * 设置用户昵称与性别
     */
    private val mSetUserNameLiveData = MutableLiveData<ReqSetUserName>()

    /**
     * 设置用户昵称与性别-回调
     */
    val onSetUserNameLiveData =
        Transformations.switchMap(mSetUserNameLiveData) { query ->
            ApiAiReposity.setUserName(this, query)
        }

    /**
     * 设置用户昵称与性别
     */
    fun setUserName(reqSetUserName: ReqSetUserName) {
        mSetUserNameLiveData.value = reqSetUserName
    }
    ///////////////////////////////////////

    /**
     * 设置用户头像
     */
    private val mSetUserHeadImgLiveData = MutableLiveData<ReqSetUserHeadImg>()

    /**
     * 设置用户头像-回调
     */
    val onSetUserHeadImgLiveData =
        Transformations.switchMap(mSetUserHeadImgLiveData) { query ->
            ApiAiReposity.setUserHeadImg(this, query)
        }

    /**
     * 设置用户头像
     */
    fun setUserHeadImg(reqSetUserHeadImg: ReqSetUserHeadImg) {
        mSetUserHeadImgLiveData.value = reqSetUserHeadImg
    }
    ///////////////////////////////////////

    /** 摇一摇id */
    var mShakeId: String = ""

    /** 摇一摇结果 */
    var mShakeResultUserInfo: RevObjShakeUserInfo? = null

    /**
     * 开始摇一摇
     */
    private val mStartShakeLiveData = MutableLiveData<ReqAiBase>()

    /**
     * 开始摇一摇-回调
     */
    val onStartShakeLiveData =
        Transformations.switchMap(mStartShakeLiveData) { query ->
            ApiAiReposity.startShake(this, query)
        }

    /**
     * 开始摇一摇
     */
    fun startShake(reqAiBase: ReqAiBase) {
        mStartShakeLiveData.value = reqAiBase
    }
    ///////////////////////////////////////

    /**
     * 摇一摇返回的用户
     */
    private val mGetShakeUserInfoLiveData = MutableLiveData<ReqGetShakeUserInfo>()

    /**
     * 摇一摇返回的用户-回调
     */
    val onGetShakeUserInfoLiveData =
        Transformations.switchMap(mGetShakeUserInfoLiveData) { query ->
            ApiAiReposity.getShakeUserInfo(this, query)
        }

    /**
     * 摇一摇返回的用户
     */
    fun getShakeUserInfo(reqGetShakeUserInfo: ReqGetShakeUserInfo) {
        mGetShakeUserInfoLiveData.value = reqGetShakeUserInfo
    }
    ///////////////////////////////////////


    /**
     * 设置用户签名
     */
    private val mSetUserSignatureLiveData = MutableLiveData<ReqSetUserSignature>()

    /**
     * 设置用户签名-回调
     */
    val onSetUserSignatureLiveData =
        Transformations.switchMap(mSetUserSignatureLiveData) { query ->
            ApiAiReposity.setUserSignature(this, query)
        }

    /**
     * 设置用户签名
     */
    fun setUserSignature(reqSetUserSignature: ReqSetUserSignature) {
        mSetUserSignatureLiveData.value = reqSetUserSignature
    }
    ///////////////////////////////////////

    // 用户相册列表
    val mUserAblumList = mutableListOf<RevObjUserAblum>()

    // 用户相册列表
    val mUserAblumWithDeleteItemList = mutableListOf<RevObjUserAblum>()

    /**
     * 获取用户相册
     */
    private val mGetUserPhotosLiveData = MutableLiveData<ReqAiBase>()

    /**
     * 获取用户相册-回调
     */
    val onGetUserPhotosLiveData =
        Transformations.switchMap(mGetUserPhotosLiveData) { query ->
            ApiAiReposity.getUserPhotos(this, query)
        }

    /**
     * 获取用户相册
     */
    fun getUserPhotos(reqAiBase: ReqAiBase) {
        mGetUserPhotosLiveData.value = reqAiBase
    }
    ///////////////////////////////////////

    /**
     * 上传用户相册
     */
    private val mUploadUserPhotosLiveData = MutableLiveData<ReqUploadUserPhotos>()

    /**
     * 上传用户相册-回调
     */
    val onUploadUserPhotosLiveData =
        Transformations.switchMap(mUploadUserPhotosLiveData) { query ->
            ApiAiReposity.uploadUserPhotos(this, query)
        }

    /**
     * 上传用户相册
     */
    fun uploadUserPhotos(reqUploadUserPhotos: ReqUploadUserPhotos) {
        mUploadUserPhotosLiveData.value = reqUploadUserPhotos
    }
    ///////////////////////////////////////

    /**
     * 删除用户相册
     */
    private val mDeleteUserPhotosLiveData = MutableLiveData<ReqDeleteUserPhotos>()

    /**
     * 删除用户相册-回调
     */
    val onDeleteUserPhotosLiveData =
        Transformations.switchMap(mDeleteUserPhotosLiveData) { query ->
            ApiAiReposity.deleteUserPhotos(this, query)
        }

    /**
     * 删除用户相册
     */
    fun deleteUserPhotos(reqDeleteUserPhotos: ReqDeleteUserPhotos) {
        mDeleteUserPhotosLiveData.value = reqDeleteUserPhotos
    }
    ///////////////////////////////////////


    // 打招呼历史列表
    val mGreetHistoryList = mutableListOf<RevObjGreetHistory>()

    /**
     * 获取打招呼历史列表
     */
    private val mGetGreetHistoryListLiveData = MutableLiveData<ReqAiBase>()

    /**
     * 获取打招呼历史列表-回调
     */
    val onGetGreetHistoryListLiveData =
        Transformations.switchMap(mGetGreetHistoryListLiveData) { query ->
            ApiAiReposity.getGreetHistoryList(this, query)
        }

    /**
     * 获取打招呼历史列表
     */
    fun getGreetHistoryList(reqAiBase: ReqAiBase) {
        mGetGreetHistoryListLiveData.value = reqAiBase
    }
    ///////////////////////////////////////


    // 摇一摇历史列表
    val mShakeHistoryList = mutableListOf<RevObjShakeHistory>()

    /**
     * 获取摇到历史列表
     */
    private val mGetShakeHistoryListLiveData = MutableLiveData<ReqAiBase>()

    /**
     * 获取摇到历史列表-回调
     */
    val onGetShakeHistoryListLiveData =
        Transformations.switchMap(mGetShakeHistoryListLiveData) { query ->
            ApiAiReposity.getShakeHistoryList(this, query)
        }

    /**
     * 获取摇到历史列表
     */
    fun getShakeHistoryList(reqAiBase: ReqAiBase) {
        mGetShakeHistoryListLiveData.value = reqAiBase
    }
    ///////////////////////////////////////

    // 摇一摇历史列表
    val mChatInfoMsgList = mutableListOf<RevObjChatInfoMsg>()

    /**
     * 获取对话详情
     */
    private val mGetChatInfoLiveData = MutableLiveData<ReqChatInfo>()

    /**
     * 获取对话详情-回调
     */
    val onGetChatInfoLiveData =
        Transformations.switchMap(mGetChatInfoLiveData) { query ->
            ApiAiReposity.getChatInfo(this, query)
        }

    /**
     * 获取对话详情
     */
    fun getChatInfo(reqChatInfo: ReqChatInfo) {
        mGetChatInfoLiveData.value = reqChatInfo
    }
    ///////////////////////////////////////

    /**
     * 打招呼
     */
    private val mToGreetLiveData = MutableLiveData<ReqToGreet>()

    /**
     * 打招呼-回调
     */
    val onToGreetLiveData =
        Transformations.switchMap(mToGreetLiveData) { query ->
            ApiAiReposity.toGreet(this, query)
        }

    /**
     * 打招呼
     */
    fun toGreet(reqToGreet: ReqToGreet) {
        mToGreetLiveData.value = reqToGreet
    }
    ///////////////////////////////////////

    /**
     * 回复消息
     */
    private val mToReplyLiveData = MutableLiveData<ReqToReply>()

    /**
     * 回复消息-回调
     */
    val onToReplyLiveData =
        Transformations.switchMap(mToReplyLiveData) { query ->
            ApiAiReposity.toReply(this, query)
        }

    /**
     * 回复消息
     */
    fun toReply(reqToReply: ReqToReply) {
        mToReplyLiveData.value = reqToReply
    }
    ///////////////////////////////////////

    /**
     * 记录看完广告
     */
    private val mSaveLookedAdvertLiveData = MutableLiveData<ReqLookedAdvert>()

    /**
     * 记录看完广告-回调
     */
    val onSaveLookedAdvertLiveData =
        Transformations.switchMap(mSaveLookedAdvertLiveData) { query ->
            ApiAiReposity.saveLookedAdvert(this, query)
        }

    /**
     * 回复消息
     */
    fun saveLookedAdvert(reqLookedAdvert: ReqLookedAdvert) {
        mSaveLookedAdvertLiveData.value = reqLookedAdvert
    }
    ///////////////////////////////////////

    /**
     * 获取用户vip信息
     */
    private val mGetUserVipInfoLiveData = MutableLiveData<ReqAiBase>()

    /**
     * 获取用户vip信息-回调
     */
    val onGetUserVipInfoLiveData =
        Transformations.switchMap(mGetUserVipInfoLiveData) { query ->
            ApiAiReposity.getUserVipInfo(this, query)
        }

    /**
     * 获取用户vip信息
     */
    fun getUserVipInfo(reqAiBase: ReqAiBase) {
        mGetUserVipInfoLiveData.value = reqAiBase
    }
    ///////////////////////////////////////

    /** 订单号-商品id */
    var mPayOrderId: String = ""
    var mPayBuyId: String = ""

    /**
     * 获取商品id
     */
    private val mGetPayOrderIdLiveData = MutableLiveData<ReqAiBase>()

    /**
     * 获取商品id-回调
     */
    val onGetPayOrderIdLiveData =
        Transformations.switchMap(mGetPayOrderIdLiveData) { query ->
            ApiAiReposity.getPayOrderId(this, query)
        }

    /**
     * 获取商品id
     */
    fun getPayOrderId(reqAiBase: ReqAiBase) {
        mGetPayOrderIdLiveData.value = reqAiBase
    }
    ///////////////////////////////////////

    /**
     * 保存订单支付信息
     */
    private val mSavePayOrderInfoLiveData = MutableLiveData<ReqSavePayOrderInfo>()

    /**
     * 保存订单支付信息-回调
     */
    val onSavePayOrderInfoLiveData =
        Transformations.switchMap(mSavePayOrderInfoLiveData) { query ->
            ApiAiReposity.savePayOrderInfo(this, query)
        }

    /**
     * 保存订单支付信息
     */
    fun savePayOrderInfo(reqSavePayOrderInfo: ReqSavePayOrderInfo) {
        mSavePayOrderInfoLiveData.value = reqSavePayOrderInfo
    }
    ///////////////////////////////////////

    /**
     * 订单支付成功
     */
    private val mPayOrderInfoSuccessLiveData = MutableLiveData<ReqSavePayOrderInfo>()

    /**
     * 订单支付成功-回调
     */
    val onPayOrderInfoSuccessLiveData =
        Transformations.switchMap(mPayOrderInfoSuccessLiveData) { query ->
            ApiAiReposity.payOrderInfoSuccess(this, query)
        }

    /**
     * 订单支付成功
     */
    fun payOrderInfoSuccess(reqSavePayOrderInfo: ReqSavePayOrderInfo) {
        mPayOrderInfoSuccessLiveData.value = reqSavePayOrderInfo
    }
    ///////////////////////////////////////

    /**
     * 消息-删除招呼记录
     */
    private val mDeleteGreetRecordLiveData = MutableLiveData<ReqDeleteGreetRecord>()

    /**
     * 消息-删除招呼记录-回调
     */
    val onDeleteGreetRecordLiveData =
        Transformations.switchMap(mDeleteGreetRecordLiveData) { query ->
            ApiAiReposity.deleteGreetRecord(this, query)
        }

    /**
     * 消息-删除招呼记录
     */
    fun deleteGreetRecord(reqDeleteGreetRecord: ReqDeleteGreetRecord) {
        mDeleteGreetRecordLiveData.value = reqDeleteGreetRecord
    }
    ///////////////////////////////////////

    /**
     * 消息-删除摇一摇记录
     */
    private val mDeleteShakeRecordLiveData = MutableLiveData<ReqDeleteShakeRecord>()

    /**
     * 消息-删除摇一摇记录-回调
     */
    val onDeleteShakeRecordLiveData =
        Transformations.switchMap(mDeleteShakeRecordLiveData) { query ->
            ApiAiReposity.deleteShakeRecord(this, query)
        }

    /**
     * 消息-删除摇一摇记录
     */
    fun deleteShakeRecord(reqDeleteShakeRecord: ReqDeleteShakeRecord) {
        mDeleteShakeRecordLiveData.value = reqDeleteShakeRecord
    }
    ///////////////////////////////////////

    /**
     * 消息-阅读打招呼消息
     */
    private val mReadGreetMsgLiveData = MutableLiveData<ReqReadGreetMsg>()

    /**
     * 消息-阅读打招呼消息-回调
     */
    val onReadGreetMsgLiveData =
        Transformations.switchMap(mReadGreetMsgLiveData) { query ->
            ApiAiReposity.readGreetMsg(this, query)
        }

    /**
     * 消息-阅读打招呼消息
     */
    fun readGreetMsg(reqReadGreetMsg: ReqReadGreetMsg) {
        mReadGreetMsgLiveData.value = reqReadGreetMsg
    }
    ///////////////////////////////////////

    /**
     * 消息-获取用户是否有新消息
     */
    private val mGetLatestGreetMsgLiveData = MutableLiveData<ReqSavePayOrderInfo>()

    /**
     * 消息-获取用户是否有新消息-回调
     */
    val onGetLatestGreetMsgLiveData =
        Transformations.switchMap(mGetLatestGreetMsgLiveData) { query ->
            ApiAiReposity.getLatestGreetMsg(this, query)
        }

    /**
     * 消息-获取用户是否有新消息
     */
    fun getLatestGreetMsg(reqSavePayOrderInfo: ReqSavePayOrderInfo) {
        mGetLatestGreetMsgLiveData.value = reqSavePayOrderInfo
    }
    ///////////////////////////////////////

    /**
     * 用户反馈图片列表
     */
    val mFeedbackImageList = mutableListOf<UserFeedbackImage>()

    /**
     * 提交用户反馈
     */
    private val mSubmitFeedbackLiveData = MutableLiveData<ReqSubmitFeedback>()

    /**
     * 提交用户反馈-回调
     */
    val onSubmitFeedbackLiveData =
        Transformations.switchMap(mSubmitFeedbackLiveData) { query ->
            ApiAiReposity.submitFeedback(this, query)
        }

    /**
     * 提交用户反馈
     */
    fun submitFeedback(reqSubmitFeedback: ReqSubmitFeedback) {
        mSubmitFeedbackLiveData.value = reqSubmitFeedback
    }

    ///////////////////////////////////////

}